//
//  XJTabBar.m
//  weiboOC
//
//  Created by 徐绩 on 16/4/17.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "XJTabBar.h"

@implementation XJTabBar

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

#pragma mark - 添加加号按钮
-(void)setupUI{

    self.addBtn = [[UIButton alloc]init];
    
    [self.addBtn addTarget:self action:@selector(didClickAddBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [self.addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [self.addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];
    [self.addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];
   
    [self.addBtn sizeToFit];
    [self addSubview:self.addBtn];
}

#pragma mark - 加号按钮的点击方法
-(void)didClickAddBtn{

    self.addBtnClickBlock();
}

#pragma mark - 设置子控件frame
-(void)layoutSubviews{

    [super layoutSubviews];
    
    self.addBtn.center = CGPointMake(self.frame.size.width *0.5, self.frame.size.height *0.5);
    
    CGFloat itemW = self.frame.size.width /5;
    int index = 0;
    
    for (UIView *item in self.subviews) {
        
        if ([item isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            CGRect itemFrame = item.frame;
            itemFrame.size.width = itemW;
            itemFrame.origin.x = index * itemW;
            item.frame = itemFrame;
            
            index++;
            
            if (index == 2) {
                
                index++;
            }
            
        }

    }

}


@end
